﻿using System;
using System.Collections.Generic;

namespace System
{
	public partial struct V3D
	{
		public B_Matrix ToMatrixHoriz()
		{
			B_Matrix Res = new B_Matrix(1, 4);
			Res[0, 0] = X;
			Res[0, 1] = Y;
			Res[0, 2] = Z;
			Res[0, 3] = 1;
			return Res;
		}
		public B_Matrix ToMatrixVert()
		{
			B_Matrix Res = new B_Matrix(4, 1);
			Res[0, 0] = X;
			Res[1, 0] = Y;
			Res[2, 0] = Z;
			Res[3, 0] = 1;
			return Res;
		}
		public static V3D FromMatrix(B_Matrix M)
		{
			if ((M.NCol == 4 || M.NCol == 3) && M.NRow == 1)
				return new V3D(M[0, 0], M[0, 1], M[0, 2]);
			else if (M.NCol == 1 && (M.NRow == 4 || M.NRow == 3))
				return new V3D(M[0, 0], M[1, 0], M[2, 0]);
			else
				throw new Exception("Invalid matrix input");
		}
		public static V3D operator *(V3D V, B_Matrix M)
		{
			B_Matrix m = V.ToMatrixHoriz();
			B_Matrix res = m * M;
			return new V3D(res[0, 0], res[0, 1], res[0, 2]);
		}
		public static V3D operator *(B_Matrix M, V3D V)
		{
			B_Matrix m = V.ToMatrixVert();
			B_Matrix res = M * m;
			return new V3D(res[0, 0], res[1, 0], res[2, 0]);
		}
	}
}